package com.bfxy.rabbitmq.dlx;

import com.bfxy.rabbitmq.util.RabbitUtil;
import com.rabbitmq.client.Channel;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by deng_wb on 2020/3/14
 */
@SuppressWarnings("all")
public class Consumer {

    public static void main(String[] args)throws Exception {

        Channel channel = RabbitUtil.consumerChannel();

        String exchangeName = "test_dlx_exchange";
        String routingKey = "dlx.#";
        String queueName = "test_dlx_queue";

        channel.exchangeDeclare(exchangeName,"topic",true,false,null );

        Map<String,Object> agruments = new HashMap<>();
        agruments.put("x-dead-letter-exchange","dlx.exchange");

        //这个agruments属性，要设置到声明队列上
        channel.queueDeclare(queueName,true,false,false,agruments);
        channel.queueBind(queueName,exchangeName,routingKey);

        // 要进行死信队列的声明
        channel.exchangeDeclare("dlx.exchange","topic",true,false,null);
        channel.queueDeclare("dlx.queue",true,false,false,null);
        channel.queueBind("dlx.queue","dlx.exchange","#");

        channel.basicConsume(queueName,true,new MyConsumer(channel));

    }
}
